package cn.com.tomato.controller;

import cn.com.tomato.service.StatisticsService;
import cn.com.tomato.utils.NumberUtils;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: chenlj
 * @CreateTime: 2024-09-03 14:26
 * @Description:
 */
@RestController
@RequestMapping("/tomato/statistics")
public class StatisticsController extends BaseController{
    @Autowired
    private StatisticsService statisticsService;

    /**
     * 获取累积数据
     * @param json
     * @return
     */
    @PostMapping("/accumulateData")
    public Object accumulateData(@RequestBody JSONObject json){
        Map<String, Object> result = statisticsService.getAccumulateData(json.getLong("id"));
        result.put("allFocusAverage", NumberUtils.format(result.get("allFocusAverage").toString())) ;
        return success(result);
    }

    /**
     * 获取当日数据
     */
    @PostMapping("/todayData")
    public Object todayData(@RequestBody JSONObject json){
        return success(statisticsService.todayData(json.getLong("id")));
    }

    /**
     * 获取专注分布数据
     * @return
     */
    @PostMapping("/focusDistribution")
    public Object focusDistribution(@RequestBody JSONObject json) {
        logger.info("focusDistribution:{}",json);
        return success(statisticsService.focusDistribution(json));
    }

    /**
     * 年度统计
     */
    @PostMapping("/yearStatistics")
    public Object yearStatistics(@RequestBody JSONObject json) {
        return success(statisticsService.yearStatistics(json));
    }

    /**
     * 月度统计
     */
    @PostMapping("/monthStatistics")
    public Object monthStatistics(@RequestBody JSONObject json) {
        return success(statisticsService.monthStatistics(json));
    }

    /**
     * 失败原因统计
     * @param json
     * @return
     */
    @PostMapping("/stopStatistics")
    public Object stopStatistics(@RequestBody JSONObject json) {
        return success(statisticsService.stopStatistics(json));
    }



}
